const {con} = require('../db/db');

async function uploadImgs(name,image,size,type) {
    const sql = `insert into images(name,image,size,type) values("${name}","${image}","${size}","${type}");`;

    await con.execute(sql);
}

async function getImgList(page) {
    const sql = `select * from images order by id limit ${(page-1)*10},10;`;

    const total = `select * from images;`;

    let [rows] = await con.execute(sql);

    let [totals] = await con.execute(total);

    return {data:rows,total:totals.length}
}

async function delImgById(id) {
    const selsql = `select image from images where id=${id};`,
    sql = `delete from images where id=${id};`;

    let res = '';

    res = await con.execute(selsql);

    await con.execute(sql);

    return res;
}

module.exports={
    uploadImgs,
    getImgList,
    delImgById
}